<?php

/**
 * this class provides some unseful functions for working with tabs and their content
 * @author		ungerboeck simon <su@militaerversand.at>
 *
 */
class Tab {
    private $title = null;
    private $content = null;
    private $tabbar = null;
    private $id = null;
    private $closable = null;
    private $href = null;
    private $afterLoadFunc = null;

    /************************************************************************
     ************************** PUBLIC FUNCTIONS ****************************
     ************************************************************************/

    /**
     * sets the title, id and closable
     * @param         string         $title
     * @param         string         $id
     */
    public function __construct($title, $id = null) {
        $this->title = $title;
        $this->id = $id;
        $this->closable = false;
    }
    
    
    /**
     * forms the ajax url for current tab and sets the href
     * @param 		string		 $target
     * @param 		int			 $id
     */
  	 public function formUrl($target, $id){
  	 	$href = \Module::getAjaxUrl() . '?T=' . $target . '&ID=' . $id;
   		$this->setHref($href);
  	 }


    /**
     * adds a tabbar to the tab
     * @param         mixed         $tabbar
     */
    public function addTabbar(Tabbar $tabbar) {
        $this->tabbar = $tabbar;
    }


    /**
     * creates the tab with his content or a subtabbar
     * @return         string        $output
     */
    public function create() {
        $output = '<div ';
        $output .= (isset($this->id) ? 'id="' . $this->id . '" ' : '');
        $output .= (isset($this->href) ? 'href="' . $this->href . '" ' : '');
        $output .= (isset($this->title) ? 'title="' . $this->title . '" ' : '');
        $output .= (isset($this->closable) ? 'closable="' . (($this->closable) ? 'true' : 'false') . '" ' : '');
        $output .= ((isset($this->content) and !isset($this->tabbar)) ? 'style="padding: 10px" ' : 'style="padding: 0px" ');
        $output .= ((isset($this->afterLoadFunc)) ? 'data-options="onLoad: ' . $this->afterLoadFunc . '"' : '');
        $output .= '>';
        $output .= ((isset($this->content) and !isset($this->tabbar)) ? $this->content : '');
        $output .= ((!isset($this->content) and isset($this->tabbar)) ? $this->tabbar->create() : '');
        $output .= '</div>';
        return $output;
    }
    
    
    


    /************************************************************************
     **************************** GETTER / SETTER ***************************
     ************************************************************************/

    public function setId($id) {
        $this->id = $id;
    }


    public function setContent($html) {
        $this->content = $html;
    }


    public function setTitle($title) {
        $this->title = $title;
    }


    public function setClosable($closable) {
        $this->closable = $closable;
    }
    
    
    public function setHref($href){
        $this->href = $href;
    }
    
    
    public function setAfterLoadFunc($function){
    	$this->afterLoadFunc = $function;
    }


    public function getId() {
        return $this->id;
    }


    public function getContent() {
        return $this->content;
    }


    public function getTitle() {
        return $this->title;
    }


    public function getTabbar() {
        return $this->tabbar;
    }


    public function isClosable() {
        return $this->closable;
    }

    
    public function getBeforeCloseFunction(){
        return $this->beforeCloseFunction();
    }
    
    
    public function getHref(){
        return $this->href;
    }
    
    public function getAfterLoadFunc(){
    	return $this->afterLoadFunc;
    }

    /************************************************************************
     ************************** PRIVATE FUNCTIONS ***************************
     ************************************************************************/
}
?>